<?php
    /**
     * CHECK DUPLICATE STORE NAME
     */
    if($_GET['post_type'] == 'store')
        add_action('admin_footer', 'check_dup_store_title');
    function check_dup_store_title()
    { ?>
    <script type="text/javascript">
    
    jQuery(document).ready(function($)
    {
        var ip = $("#title");
        ip.blur(function(){
            var st_name = ip.val();
            var data = {
        		action: 'action_check_st_name',
        		vl: st_name
            };
            $.post(ajaxurl, data, function(rs) {
                if(rs != 0)
                {
                    alert('Maybe duplicate store name. re-check plz !');
                }
            })
        })
        
    })
    </script>
    <?php
    }
    // For loged user only
    add_action('wp_ajax_action_check_st_name','cb_check_storename');
    function cb_check_storename()
    {
        $st_name = $_POST['vl'];
        global $wpdb;
        $qr = "select ID from {$wpdb->posts} where post_title = '{$st_name}' and post_type = 'store' and post_status = 'publish'";
        $rs = $wpdb->get_row($qr);
        if($rs != null)
            echo $rs->ID;
        else
            echo 0;
        die();
    }
?>